<?php

include('inc/class.sql.php');
include('inc/class.auth.php');
include('inc/db.php');

$sql_conn = new mysql($host,$db,$user,$pass);

?>

<html>
<title>To-do List</title>
<?php include('inc/theme.php'); ?>
<br />
<p style="font-size:40px;font-family:'Roboto Slab'">CREATE A USER</p>
  <form method="post">
    <table>
      <tr>
        <td>
          <input type="text" name="username" placeholder="Username"><br />
        </td><td>
          <input type="password" name="password" placeholder="Password"><br />
        </td><td>
          <input type="submit" value="Sign Up">
        </td>
      </tr>
    </table>
  </form>

<?php if (!empty($_POST)) {

    $username = $_POST['username'];
    $password = md5($_POST['password']);

    $auth = new auth($sql_conn,$username,$password);

    if (empty($username) || empty($password)) {

        print "Username and password are both required fields.<br />";

    } else {

        if ($auth->check_user($username)) {

            print "User ".$username." already exists.<br />";

        } else {

            $auth->create_user();

            if ($auth->check_user($username)) {

                print "User created successfully!<br />";

            } else {

                print "User could not be created.<br />";
            }

        }

    }

} ?>

<a href="index.php">Back to login page</a>

</body></html>
